﻿<Window x:Uid="Window_1" x:Class="Up2dateConsole.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Up2dateConsole"
        xmlns:service="clr-namespace:Up2dateConsole.ServiceReference"
        xmlns:tb="http://www.hardcodet.net/taskbar" 
        xmlns:helpers="clr-namespace:Up2dateConsole.Helpers" 
        xmlns:toolBar="clr-namespace:Up2dateConsole.ToolBar" 
        xmlns:statusBar="clr-namespace:Up2dateConsole.StatusBar" 
        mc:Ignorable="d"
        ShowInTaskbar="True"
        Icon="Images/Logo.ico"
        Title="RITMS UP2DATE Console" 
        Height="600" Width="1000"
        MinHeight="300" MinWidth="800"
        WindowStartupLocation="CenterScreen"
        d:DataContext="{d:DesignInstance local:MainWindowViewModel}">

    <Window.Resources>
        <ResourceDictionary x:Uid="ResourceDictionary_1">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary x:Uid="ResourceDictionary_2" Source="Styles.xaml"/>
                <ResourceDictionary x:Uid="ResourceDictionary_3" Source="Texts.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <BooleanToVisibilityConverter x:Uid="BooleanToVisibilityConverter_1" x:Key="BooleanToVisibilityConverter"/>
            <helpers:NullToVisibilityConverter x:Uid="helpers:NullToVisibilityConverter_1" x:Key="NullToVisibilityConverter"/>
            <helpers:InvertBooleanToVisibilityConverter x:Uid="helpers:InvertBooleanToVisibilityConverter_1" x:Key="InvertBooleanToVisibilityConverter"/>
        </ResourceDictionary>
    </Window.Resources>

    <Grid x:Uid="Grid_1">
        <Grid.RowDefinitions>
            <RowDefinition x:Uid="RowDefinition_1"/>
            <RowDefinition x:Uid="RowDefinition_2" Height="Auto"/>
        </Grid.RowDefinitions>

        <tb:TaskbarIcon x:Uid="tb:TaskbarIcon_1" Visibility="Visible"
                        IconSource="{Binding TaskbarIcon}"
                        MenuActivation="RightClick"
                        LeftClickCommand="{Binding ShowConsoleCommand}"
                        DoubleClickCommand="{Binding ShowConsoleCommand}"
                        ToolTipText="{Binding TaskbarIconText}">
            <tb:TaskbarIcon.ContextMenu>
                <ContextMenu x:Uid="ContextMenu_1">
                    <MenuItem x:Uid="MenuItem_1" Header="Show console" Command="{Binding ShowConsoleCommand}"/>
                    <Separator x:Uid="Separator_2" Visibility="{Binding IsAdminMode, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    <MenuItem x:Uid="MenuItem_3" Header="Start service" Command="{Binding StartServiceCommand}"
                              Visibility="{Binding IsAdminMode, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    <MenuItem x:Uid="MenuItem_4" Header="Stop service" Command="{Binding StopServiceCommand}"
                              Visibility="{Binding IsAdminMode, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    <MenuItem x:Uid="MenuItem_5" Header="Settings..." Command="{Binding SettingsCommand}"
                              Visibility="{Binding IsAdminMode, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    <MenuItem x:Uid="MenuItem_7" Header="Leave admin mode" Command="{Binding LeaveAdminModeCommand}"
                              Visibility="{Binding IsAdminMode, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    <MenuItem x:Uid="MenuItem_6" Header="To admin mode..." Command="{Binding EnterAdminModeCommand}"
                              Visibility="{Binding IsAdminMode, Converter={StaticResource InvertBooleanToVisibilityConverter}}">
                        <MenuItem.Icon>
                            <Image x:Uid="Image_2" Source="Images/UAC.png"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator x:Uid="Separator_1"/>
                    <MenuItem x:Uid="MenuItem_2" Header="Quit" Command="{Binding QuitCommand}"/>
                </ContextMenu>
            </tb:TaskbarIcon.ContextMenu>
        </tb:TaskbarIcon>

        <Grid x:Uid="Grid_2">
            <Grid.RowDefinitions>
                <RowDefinition x:Uid="RowDefinition_3" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_4"/>
            </Grid.RowDefinitions>
            <Grid x:Uid="Grid_3" Margin="10,5" >
                <TextBlock x:Uid="TextBlock_1" VerticalAlignment="Center" Text="Software packages:"/>
                <toolBar:ToolBar x:Uid="toolBar:ToolBar_1" HorizontalAlignment="Right" VerticalAlignment="Center" DataContext="{Binding ToolBar}"/>
            </Grid>
            <DataGrid x:Uid="DataGrid_1" Grid.Row="1" Margin="10,0,10,4" 
                        Background="White"
                        SelectionMode="Single"
                        RowHeight="20"
                        SelectionUnit="FullRow"
                        AutoGenerateColumns="False"
                        GridLinesVisibility="None"
                        CanUserAddRows="False"
                        CanUserDeleteRows="False"
                        CanUserReorderColumns="False"
                        CanUserResizeRows="False"
                        RowHeaderWidth="0"
                        IsReadOnly="True"
                        IsSynchronizedWithCurrentItem="True"
                        ItemsSource="{Binding AvailablePackages}">
                <DataGrid.Columns>
                    <DataGridTextColumn x:Uid="DataGridTextColumn_1" Header="Package" Binding="{Binding Filename}" Width="2*"/>
                    <DataGridTextColumn x:Uid="DataGridTextColumn_2" Header="Product name" Binding="{Binding ProductName}" Width="2*"/>
                    <DataGridTextColumn x:Uid="DataGridTextColumn_3" Header="Publisher" Binding="{Binding Publisher}" Width="1*"/>
                    <DataGridTextColumn x:Uid="DataGridTextColumn_4" Header="Version" Binding="{Binding Version}" MinWidth="80"/>
                    <DataGridTemplateColumn x:Uid="DataGridTextColumn_7" Header="Status" MinWidth="100" SortMemberPath="Status">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate x:Uid="DataTemplate_1">
                                <StackPanel x:Uid="StackPanel_7" Orientation="Horizontal">
                                    <TextBlock x:Uid="TextBlock_8" Text="{Binding Status}">
                                        <TextBlock.Style>
                                            <Style x:Uid="Style_4" TargetType="{x:Type TextBlock}">
                                                <Style.Triggers>
                                                    <DataTrigger x:Uid="DataTrigger_3" Binding="{Binding PackageStatus}" Value="{x:Static service:PackageStatus.WaitingForConfirmation}">
                                                        <Setter x:Uid="Setter_8" Property="Foreground" Value="DarkOrange"/>
                                                    </DataTrigger>
                                                    <DataTrigger x:Uid="DataTrigger_4" Binding="{Binding PackageStatus}" Value="{x:Static service:PackageStatus.WaitingForConfirmationForced}">
                                                        <Setter x:Uid="Setter_9" Property="Foreground" Value="DarkOrange"/>
                                                    </DataTrigger>
                                                    <DataTrigger x:Uid="DataTrigger_1" Binding="{Binding PackageStatus}" Value="{x:Static service:PackageStatus.Failed}">
                                                        <Setter x:Uid="Setter_6" Property="Foreground" Value="Red"/>
                                                    </DataTrigger>
                                                    <DataTrigger x:Uid="DataTrigger_2" Binding="{Binding PackageStatus}" Value="{x:Static service:PackageStatus.Installed}">
                                                        <Setter x:Uid="Setter_7" Property="Foreground" Value="Green"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>   
                                    </TextBlock>
                                    <TextBlock x:Uid="TextBlock_9" Margin="8,0,0,0" 
                                               Style="{StaticResource AwesomeIcon}" Foreground="SteelBlue" FontSize="14"
                                               Text="{StaticResource InfoCircleIcon}" 
                                               Visibility="{Binding ExtraInfo, Converter={StaticResource NullToVisibilityConverter}}"
                                               ToolTip="{Binding ExtraInfo}"/>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
                <DataGrid.Resources>
                    <Style x:Uid="Style_2" TargetType="DataGridCell">
                        <Setter x:Uid="Setter_3" Property="Focusable" Value="False" />
                        <Setter x:Uid="Setter_4" Property="IsTabStop" Value="False" />
                    </Style>
                    <Style x:Uid="Style_3" TargetType="DataGridRow">
                        <Setter x:Uid="Setter_5" Property="IsSelected" Value="{Binding IsSelected}" />
                    </Style>
                </DataGrid.Resources>
            </DataGrid>
        </Grid>

        <statusBar:StatusBar x:Uid="local:StatusBar_1" Grid.Row="1" Margin="10,0,10,10" DataContext="{Binding StatusBar}"/>
    </Grid>
</Window>
